import { _decorator, Component, Label, Node } from 'cc';
import { Village } from '../entity/Village';
import { UIManager } from '../common/UIManager';
import { PrefabEnum } from '../common/PrefabEnum';
import { VillageInformation } from '../world/VillageInformation';
import { MapZone } from '../entity/MapZone';
const { ccclass, property } = _decorator;

@ccclass('PalaceVillage')
export class PalaceVillage extends Component {
    @property(Label)
    index:Label
    @property(Label)
    villageName:Label
    @property(Label)
    coord:Label
    @property(Label)
    people:Label

    village:Village

    start() {
        this.node.on(Node.EventType.TOUCH_END, this.onClick, this)
    }

    setData(village:Village, num:number){
        this.village = village

        this.index.string = num + ''
        this.villageName.string = village.name
        this.coord.string = `( ${village.x} | ${village.y} )`
        this.people.string = village.people + ''
    }

    async onClick(){
        console.log(this.village)

        let ui = await UIManager.instance.openUI(PrefabEnum.VillageInformation)
        let zone = MapZone.createByObj(this.village)
        zone.typeId = 28
        ui.getComponent(VillageInformation).setData(zone)
    }
}


